//
//  ZQPendingOrderTableViewCell.m
//  jianzhik
//
//  Created by huami on 2018/8/30.
//  Copyright © 2018年 WKWebView. All rights reserved.
//
#import "ZQProcessedOrderPage.h"
#import "ZQQrcodeGenerationPage.h"
#import "ZQ_GetCurrentViewNavTool.h"
#import "ZQPendingOrderTableViewCell.h"
#import "UIView+zq_extension.h"
#import <MJRefresh/MJRefresh.h>
#import "UIHelper.h"
@implementation ZQPendingOrderTableViewCell


- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setFrame:(CGRect)frame
{
    frame.size.height -= 5;
    [super setFrame:frame];
//    self.reasonBtn.alpha = 0;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (IBAction)lookReasonClick:(id)sender {
    [UIHelper showTipsWithText:self.penModel.Errors inView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view];
}

- (void)setPenModel:(ZQPendingModel *)penModel
{
    _penModel = penModel;
    self.ewmBtn.hidden = NO;
    self.reasonBtn.hidden = YES;
    self.ddhLabel.text = [NSString stringWithFormat:@"订单号:%@",penModel.Billid];
    self.bzLabel.text = [NSString stringWithFormat:@"币种:%@",penModel.Symbol];
    self.currentLabel.text = [self statusForString:penModel.Status];
    if ([penModel.Status isEqualToString:@"30"]) {
        self.currentLabel.textColor = [UIColor redColor];
    } else {
        self.currentLabel.textColor = [UIColor stringToColor:@"#505050"];
    }
    
    if ([penModel.Status isEqualToString:@"30"]) {
        self.ewmBtn.hidden = NO;
        self.reasonBtn.hidden = NO;
        [self.ewmBtn setTitle:@"重新处理" forState:UIControlStateNormal];
    } else if ([penModel.Status isEqualToString:@"10"]){
        self.ewmBtn.hidden = NO;
        self.reasonBtn.hidden = YES;
    } else {
//        if ([[ZQ_GetCurrentViewNavTool viewControllerSupportView:self] isKindOfClass:[ZQProcessedOrderPage class]]) {
//            self.ewmBtn.alpha = 0;
//            self.reasonBtn.alpha = 0;
//        } else {
//            self.ewmBtn.alpha = 1;
//            self.reasonBtn.alpha = 0;
//        }
        self.ewmBtn.hidden = YES;
        self.reasonBtn.hidden = YES;
    }
    
    
    self.fromValueLable.text = penModel.From;
    self.toValueLabel.text = penModel.To;
    self.bdCountLabel.text = [NSString stringWithFormat:@"%f",penModel.Amount];

}

- (NSString *)statusForString:(NSString *)value
{
    NSDictionary *dict = @{@"20" : @"状态：待确认",
                                @"30" : @"状态：处理失败",
                                @"40" : @"状态：已确认"
                           };
    return dict[value];
}

- (IBAction)qrcodeGenerationCilck:(UIButton *)sender
{
        [self generateEWM];
}

- (void)generateEWM
{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"Id"] = self.penModel.Id;
    [ZQAFHelper afnetworkRequestWithPostURL:@"/v1/work/getunsigne" parameters:parameters view:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view finishedBlcok:^(NSDictionary *dict) {
        //        dict[Data]
        NSDictionary *dataDict = dict[@"Data"];
        if (dataDict.count == 0) {
            [UIHelper showTipsWithText:@"查无数据" inView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view];
            return ;
        }
        [UIHelper dismissLoadingInView:[ZQ_GetCurrentViewNavTool viewControllerSupportView:self].view];
        
        ZQQrcodeGenerationPage *vc = [ZQQrcodeGenerationPage new];
        vc.penModel = self.penModel;
        vc.Unsigne = dataDict[@"Unsigne"];
        [[ZQ_GetCurrentViewNavTool currentNC] pushViewController:vc animated:YES];
    }];
}

@end
